package com.java.comprehensive;

import java.io.*;
import java.nio.ByteBuffer;

import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;

import com.java.comprehensive.util.TestUtil;

import javax.annotation.Resource;

/**
 * @program: comprehensive-service
 * @description:
 * @author: 窦绍飞
 * @create: 2022-01-13 17:47
 **/

@SpringBootTest
public class Demo {
	@Resource
	private TestUtil testUtil;


	static int _1GB = 1024 * 1024 * 1024;

	@Test
	public void test() {

	}

	public static void main(String[] args) throws IOException {
		ByteBuffer byteBuffer = ByteBuffer.allocate(_1GB);
		System.out.println("。。。分配完毕");
		System.in.read();
		System.out.println("。。。开始释放");
		byteBuffer = null;
		System.gc();
		System.in.read();
	}

	public static void readTxtFile(String filePath) {
		try {
			String encoding = "GBK";
			File file = new File(filePath);
			if (file.isFile() && file.exists()) { //判断文件是否存在
				InputStreamReader read = new InputStreamReader(
						new FileInputStream(file), encoding);//考虑到编码格式
				BufferedReader bufferedReader = new BufferedReader(read);
				String lineTxt = null;
				while ((lineTxt = bufferedReader.readLine()) != null) {
					System.out.println(lineTxt.trim());

				}
				read.close();
			} else {
				System.out.println("找不到指定的文件");
			}
		} catch (Exception e) {
			System.out.println("读取文件内容出错");
			e.printStackTrace();
		}

	}

	@org.junit.jupiter.api.Test
	public void testRead() throws IOException {
		String fileName = "E:\\txt\\饿了么商品列表.json";
		File file = new File(fileName);
		FileInputStream fis = new FileInputStream(file);
		InputStreamReader isr = new InputStreamReader(fis);
		BufferedReader br = new BufferedReader(isr);

		String line;
		while ((line = br.readLine()) != null) {
			// process the line
			System.out.println("ok");
		}
		br.close();
	}
}
